<!DOCTYPE html>
<html>
<head>
<base href="${basePath}">
<meta charset="UTF-8">
<title>修改组</title> $!{include("import_js_css.html")}
</head>
<body>
	$!{include("header.html")}
	<div class="menu_all">
		<div class="div_search_result clear">
			<div class="panel-heading" style="background: #E9E9E9;">
				<h3 class="panel-title">修改组</h3>
			</div>
			<div class="panel-form-add">
				<!-- #set(Groups group) -->
				<form class="form-horizontal" role="form" name="groupForm"
					action="yueyogaAdmin/updateMemberGroup.jhtml" method="post">
					<div class="panel-form-layout">
						<input type="hidden" name="id" value="${group.id}" required /> <label
							for="groupName" class="col-sm-1 control-label">组名</label>
						<div class="col-sm-3">
							<input type="text" class="form-control" name="name"
								id="groupName" value="${group.name}" >
						</div>
						<br /> <br /> <label for="remarks"
							class="col-sm-1 control-label">备注</label>
						<div class="col-sm-3">
							<textarea rows="3" class="form-control"
								style="height: 80px; width: 665px; resize: none;" id="remarks"
								name="remarks" >${group.remarks}</textarea>
						</div>
						<br /> <br /> <br /> <br /> <br />
						<div class="panel-btn-search">
							<button type="submit" class="btn btn-default btn-ade-default panel-mr">保存</button>
						</div>
					</div>
				</form>
			</div>
		</div>
		
		<!--#var(List<Member> members)-->
		<!--#var(PaginatedList<Member> membersGroup)-->
		<!--
		#set(
		pager = membersGroup.pager,
		totalResults = pager.getCountOfTotalResults(),
		totalPages = pager.getCountOfTotalPages() * 1,
		pageSize = pager.pageSize,
		pageNo = pager.pageNo,
		prePageNo = pager.getPrevPageNo(),
		nextPageNo = pager.getNextPageNo()
		)
		-->
		
		<div class="div_search_result clear">
		<div class="panel-heading panel-result-title">
			<h3 class="panel-title" style="width:200px;">组中会员列表</h3>
			<div class="btn-group btn-gp-default" style="width: 300px; margin-top: 2px">
				<!--#if(status=='活动结束')  -->
				<!--#else  -->
					<select id="memberSelect" name="memberSelect" data-live-search="true" class="selectpicker show-tick" data-width="200px" style="border-top-right-radius: 0px !important; float: left;">
						<!-- #for(Member mm : members) -->
						<option value="${mm.memberid}">
							${mm.name}
						</option>
						<!-- #end -->
					</select>
					
					<button id="quickGroupMemberAdd" class="btn btn-default panel-radius-none" style="height: 30px !important;" type="button">快速添加</button>
					<button id="groupMemberDelete" class="btn btn-default panel-radius-right" type="button" style="height: 30px !important; margin-left: -6px !important;">删除</button>
				<!--#end  -->
			</div>
		</div>
		
		<table class="table table-bordered table-hover table-condensed tb" style="text-align: center">
			<tr>
				<td>编号</td>
				<td>姓名</td>
				<td>英文名</td>
				<td>手机号</td>
				<td>电话</td>
				<td>性别</td>
			</tr>
			<!-- #for(Member member : membersGroup) -->
			<tr>
				<td><a href="yueyogaAdmin/toMemberDetail.jhtml?id=${member.memberid}">${member.cardnumber}</a></td>
				<td><a href="yueyogaAdmin/toMemberDetail.jhtml?id=${member.memberid}">${member.name}</a></td>
				<td><a href="yueyogaAdmin/toMemberDetail.jhtml?id=${member.memberid}">${member.nameEn}</a></td>
				<td><a href="yueyogaAdmin/toMemberDetail.jhtml?id=${member.memberid}">${member.phone}</a></td>
				<td>${member.tel}</td>
				<td>${member.sex}</td>
			</tr>
			<!-- #end -->
		</table>
		
		<div class="paging-page">
			<ul class="pagination">
				<li><a href="yueyogaAdmin/toEditMemberGroup.jhtml?groupId=${groupId}&pageNo=1">首页</a></li>
				<!-- #if(prePageNo<=1) -->
				<li class="disabled"><a href="javascript:void(0)">上一页</a></li>
				<!-- #else -->
				<li><a href="yueyogaAdmin/toEditMemberGroup.jhtml?groupId=${groupId}&pageNo=${prePageNo}">上一页</a></li>
				<!-- #end -->
				<!-- #if(nextPageNo>=totalPages) -->
				<li class="disabled"><a href="javascript:void(0)">下一页</a></li>
				<!-- #else -->
				<li><a href="yueyogaAdmin/toEditMemberGroup.jhtml?groupId=${groupId}&pageNo=${nextPageNo}">下一页</a></li>
				<!-- #end -->
				<li><a href="yueyogaAdmin/toEditMemberGroup.jhtml?groupId=${groupId}&pageNo=${totalPages}">尾页</a></li>
				<li><a>第<input id="txtPageNumber" value="${pageNo}"
						onkeydown="this.value=this.value.replace(/\D/g,'')"
						onblur="changePage(this.value)"
						onafterpaste="this.value=this.value.replace(/\D/g,'')" type="text" />页&nbsp;&nbsp;~&nbsp;&nbsp;共${totalPages}页/${totalResults}条
				</a></li>
			</ul>
		</div>
		</div>
	</div>
	
	<script type="text/javascript">
		function changePage(value) {
			value = value * 1;
			var totalPages = '${totalPages}';
			if (value > totalPages) {
				value = totalPages;
			} else if (value < 1) {
				value = 1;
			}
			$("#txtPageNumber").val(value);
			window.location.href = "yueyogaAdmin/toEditMemberGroup.jhtml?groupId=${groupId}&pageNo=" + value;
		}
		
		$(document).ready(function() {
			$("#memberSelect").select2({
				width: "160px"
			});
			
			//向组中添加会员
			$("#quickGroupMemberAdd").click(function() {
				var memberId = $("#memberSelect").val();
				var groupId = "${groupId}";
				
				//判断是否有此会员
				var flag = false;			
				$.ajax({
					async : false,
					type : "POST",
					data : {"memberId" : memberId, "groupId" : groupId},
					url : "yueyogaAdmin/getGroupMemberCount.jhtml",
					success : function(res) {
						var response = eval("(" + res + ")");
						if(response.success) {
							flag = true;
						}
					},
					error : function(a, b, c) {
						error(a + "," + b + "," + c);
					}
				});
				
				if(flag) {
					alert("会员已存在该组中！");
					return;
				}
				
				$.post(
					"yueyogaAdmin/addGroupMember.jhtml",
					{"memberId" : memberId, "groupId" : groupId},
					function(res) {
						var response = eval("(" + res + ")");
						if(response.success) {
							var d = alert(response.msg);
							setTimeout(
								function() {
									d.close().remove();
									window.location.href = "yueyogaAdmin/toEditMemberGroup.jhtml?groupId=${groupId}&pageNo=${pageNo}";
								}, 1000
							);
						}
					}
				);
			});
			
			//从组中删除会员
			$("#groupMemberDelete").click(function() {
				var memberId = $("#memberSelect").val();
				var groupId = "${groupId}";
				
				//判断是否有此会员
				var flag = false;			
				$.ajax({
					async : false,
					type : "POST",
					data : {"memberId" : memberId, "groupId" : groupId},
					url : "yueyogaAdmin/getGroupMemberCount.jhtml",
					success : function(res) {
						var response = eval("(" + res + ")");
						if(response.success) {
							flag = true;
						}
					},
					error : function(a, b, c) {
						error(a + "," + b + "," + c);
					}
				});
				
				if(!flag) {
					alert("会员已不在该组中！");
					return;
				}
				
				$.post(
					"yueyogaAdmin/deleteGroupMember.jhtml",
					{"memberId" : memberId, "groupId" : groupId},
					function(res) {
						var response = eval("(" + res + ")");
						if(response.success) {
							var d = alert(response.msg);
							setTimeout(
								function() {
									d.close().remove();
									window.location.href = "yueyogaAdmin/toEditMemberGroup.jhtml?groupId=${groupId}&pageNo=${pageNo}";
								}, 1000
							);
						}
					}
				);
			});
		});
		
	</script>
</body>
</html>